//
//  UserInfoM.m
//  YYFMMall
//
//  Created by chenzm on 2019/8/26.
//  Copyright © 2019 YuYou1. All rights reserved.
//

#import "UserInfoM.h"
#import "WZXArchiver.h"


static NSString *kUserInfo=@"kUserInfo";
@implementation UserInfoM

+(UserInfoM *)getUserInfo{
    UserInfoM * archive = [UserInfoM wzx_unArchiveToName:kUserInfo];
    if (!archive) {
        archive=[UserInfoM setDefConfig];
    }
    return archive;
}

+(BOOL)saveUserInfo:(UserInfoM *)user{
    BOOL isHave = [user wzx_archiveToName:kUserInfo];
    return isHave;
}

#pragma -mark 登陆归档

/// 用户信息归档
+(BOOL)archiveUserInfo:(NSDictionary*)dic{
    UserInfoM *archive=[UserInfoM getUserInfo];
    
    return [UserInfoM saveUserInfo:archive];
}



+(BOOL)archiveUserLogin:(NSDictionary*)dic {
    UserInfoM *archive=[UserInfoM getUserInfo];
    
    // ---- 自定义附加 -----
    archive.isLogin = YES;
    
    // ---- 后台返回 -----
    archive.token = [dic jj_stringForKey:@"token"];
    archive.userId = [dic jj_stringForKey:@"userId"];

    if (!kIsEmptyStr(dic[@"token"])) {
        [ZMSpeedy saveLocalObj:@"token" key:dic[@"token"]];
    }
    return [UserInfoM saveUserInfo:archive];
}

/// 密码归档
+(BOOL)archiveUserPsd:(NSString *)psd{
    UserInfoM *archive=[UserInfoM getUserInfo];
    archive.loginPassword = kIsEmptyStr(psd)?@"":psd;
    return [UserInfoM saveUserInfo:archive];
}




#pragma mark 清除归档
+(BOOL)clearUser{
    UserInfoM *archive= [UserInfoM setDefConfig];
    return [UserInfoM saveUserInfo:archive];
}

#pragma -mark 初始化配置
+(UserInfoM*)setDefConfig{
    UserInfoM *archive = [UserInfoM new];
    // ---- 自定义附加 -----
    archive.isLogin = NO;
    archive.loginAccount=@"";//登录名
    archive.loginPassword=@"";//登录密码
    
    // ---- 后台返回 -----
    archive.token=@"";
    archive.userId = @"";
    
#pragma mark- 用户信息

    return archive;
}






@end
